package com.app.controller.backstage;


import com.app.model.AdminUserModel;
import com.app.model.MotionVideoModel;
import com.app.service.AdminUserService;
import com.app.service.CategoryService;
import com.app.service.DaMeiSuZhouService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.app.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 大美
 */
@RestController
@RequestMapping("/admin/daMeiSuZhou")
public class AdminDaMeiSuZhouController {

    @Autowired
    private DaMeiSuZhouService daMeiSuZhouService;

    @Autowired
    AdminUserService adminUserService;
    //大美肃州管理查询
    @GetMapping("/getDaMeiSuZhouList")
    public Result<Object> getDaMeiSuZhouList(@RequestParam Integer page,
                                             @RequestParam Integer limit,
                                             @RequestParam String keyword,
                                             @RequestParam(defaultValue = "0") Integer type,
                                             @RequestParam(defaultValue = "0") Integer videoType, HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        VideoVo daMeiSuZhouList = daMeiSuZhouService.getDaMeiSuZhouList(page, limit, keyword, type, videoType);
        return Result.success(daMeiSuZhouList);
    }


    //大美肃州管理添加
    @PostMapping("/insertDaMeiSuZhou")
    public Result<Object> insertDaMeiSuZhou(@RequestParam String title,
                                            @RequestParam Integer videoType,
                                            @RequestParam Integer sort,
                                            @RequestParam String videoUrl,
                                            @RequestParam Integer status,
                                            HttpServletRequest request) {
        String token = request.getHeader("authori-zation");
        if (token == null) {
            return Result.error(405, "token不存在");
        }
        String userId = TokenUtils.verify(token);
        AdminUserModel user = adminUserService.getUserByUserId(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(406, "用户不存在");
        }
        MotionVideoModel model = new MotionVideoModel();
        model.setTitle(title);
//       type类型 1.视频  2.文章
        if (model.getVideoUrl() != null || model.getVideoUrl() !="") {
            model.setType(1);
        } else {
            model.setType(2);
        }
        model.setVideoType(videoType);
        model.setSort(sort);
        model.setVideoUrl(videoUrl);
        model.setStatus(status);
        model.setCreateTime(CommonHelp.getNowTimestamp());
        daMeiSuZhouService.insert(model);
        return Result.success("操作成功");
    }




}
